
from pygame import *
from pygame.locals import *

class Board2DRenderer:
  def __init__(self, on_color=(0,0,0), off_color=(255,255,255)):
    self.on_color = on_color
    self.off_color = off_color
  
  def render(self, screen, board):
    ncols = board.ncols
    nrows = board.nrows
    height = screen.get_height()
    width = screen.get_width()
    cell_height = height/nrows
    cell_width = width/ncols
    if(cell_width == 1):
      pxarray = PixelArray(screen)

    
    for (i, j) in board.updated:
      position = ( i * cell_height , j * cell_width )
      color = self.on_color if board._get_state(i,j) else self.off_color
      if(cell_width == 1):
        pxarray[i][j] = screen.map_rgb(color)
      else:
        draw.rect(screen, color, Rect( position, (cell_height, cell_width ) ) )
